﻿using System;
using System.Collections.Generic;
using Character;
using UnityEngine;

// Token: 0x0200023E RID: 574
public class H_VisitorExpressionData
{
	// Token: 0x06000F7C RID: 3964 RVA: 0x00062C84 File Offset: 0x00060E84
	public H_VisitorExpressionData(H_VisitorExpression owner, TextAsset loadList)
	{
		CustomDataListLoader customDataListLoader = new CustomDataListLoader();
		customDataListLoader.Load(loadList);
		int attributeNo = customDataListLoader.GetAttributeNo("状態");
		int attributeNo2 = customDataListLoader.GetAttributeNo("種類");
		int attributeNo3 = customDataListLoader.GetAttributeNo("目");
		int attributeNo4 = customDataListLoader.GetAttributeNo("口");
		int attributeNo5 = customDataListLoader.GetAttributeNo("目の開き");
		int attributeNo6 = customDataListLoader.GetAttributeNo("口の開き");
		for (int i = 0; i < customDataListLoader.GetDataNum(); i++)
		{
			string data = customDataListLoader.GetData(attributeNo, i);
			string data2 = customDataListLoader.GetData(attributeNo2, i);
			string text = customDataListLoader.GetData(attributeNo3, i);
			string text2 = customDataListLoader.GetData(attributeNo4, i);
			float eyeOpen = float.Parse(customDataListLoader.GetData(attributeNo5, i));
			float mouthOpen = float.Parse(customDataListLoader.GetData(attributeNo6, i));
			text = owner.EyeName(text);
			text2 = owner.MouthName(text2);
			if (data == "台詞")
			{
				H_VisitorExpressionData.Data_Voice data3 = new H_VisitorExpressionData.Data_Voice(data2, text, text2, eyeOpen, mouthOpen);
				this.AddVoiceData(data3);
			}
			else
			{
				this.CreateTypeData(data, data2, text, text2, eyeOpen, mouthOpen);
			}
		}
	}

	// Token: 0x06000F7D RID: 3965 RVA: 0x00062DC8 File Offset: 0x00060FC8
	private void CreateTypeData(string state, string type, string eyeType, string mouthType, float eyeOpen, float mouthOpen)
	{
		string[] array = state.Split(new char[]
		{
			','
		});
		for (int i = 0; i < array.Length; i++)
		{
			this.type_datas.Add(new H_VisitorExpressionData.Data_Type(array[i], type, eyeType, mouthType, eyeOpen, mouthOpen));
		}
	}

	// Token: 0x06000F7E RID: 3966 RVA: 0x00062E18 File Offset: 0x00061018
	private void AddVoiceData(H_VisitorExpressionData.Data_Voice data)
	{
		if (!this.voice_datas.ContainsKey(data.voice))
		{
			this.voice_datas.Add(data.voice, new H_VisitorExpressionData.Data_Voice_Set());
		}
		this.voice_datas[data.voice].Add(data);
	}

	// Token: 0x06000F7F RID: 3967 RVA: 0x00062E68 File Offset: 0x00061068
	public H_VisitorExpressionData.Data ChangeExpression(Human human, string voiceFile, float duration)
	{
		if (!this.voice_datas.ContainsKey(voiceFile))
		{
			return null;
		}
		H_VisitorExpressionData.Data_Voice_Set data_Voice_Set = this.voice_datas[voiceFile];
		int no = UnityEngine.Random.Range(0, data_Voice_Set.Count);
		H_VisitorExpressionData.Data data = data_Voice_Set[no];
		if (data != null)
		{
			human.ExpressionPlay(0, data.eyeType, duration);
			human.blink.LimitMax = data.eyeOpen * 0.01f;
			human.lipSync.RelaxOpen = data.mouthOpen * 0.01f;
			string mouthType = data.mouthType;
			human.ExpressionPlay(1, mouthType, duration);
			human.lipSync.Hold = human.Gag;
			human.head.ResetMouth(human.Gag);
			TONGUE_TYPE tongueType = TONGUE_TYPE.FACE;
			human.SetTongueType(tongueType);
		}
		return data;
	}

	// Token: 0x06000F80 RID: 3968 RVA: 0x00062F2C File Offset: 0x0006112C
	public H_VisitorExpressionData.Data ChangeExpression(Human human, H_VisitorExpression.TYPE type, float duration)
	{
		H_VisitorExpressionData.Data data = null;
		List<H_VisitorExpressionData.Data> list = new List<H_VisitorExpressionData.Data>();
		H_VisitorExpression.STATE state = (H_VisitorExpression.STATE)0;
		if (human.sex == SEX.FEMALE)
		{
			Female female = human as Female;
			state = ((!female.IsFloped()) ? H_VisitorExpression.STATE.RESIST : H_VisitorExpression.STATE.FLIP);
		}
		foreach (H_VisitorExpressionData.Data_Type data_Type in this.type_datas)
		{
			if ((data_Type.state & state) != (H_VisitorExpression.STATE)0 && data_Type.type == type)
			{
				list.Add(data_Type);
			}
		}
		if (list.Count > 0)
		{
			int index = UnityEngine.Random.Range(0, list.Count);
			data = list[index];
		}
		if (data != null)
		{
			human.lipSync.Hold = human.Gag;
			human.head.ResetMouth(human.Gag);
			human.SetTongueType(TONGUE_TYPE.FACE);
			human.ExpressionPlay(0, data.eyeType, duration);
			human.blink.LimitMax = data.eyeOpen * 0.01f;
			human.lipSync.RelaxOpen = data.mouthOpen * 0.01f;
			human.ExpressionPlay(1, data.mouthType, duration);
		}
		else
		{
			GlobalData.Debug_LogError("没有合适的表情:" + state);
		}
		return data;
	}

	// Token: 0x04001061 RID: 4193
	private static readonly string[] StateStrs = new string[]
	{
		"抵抗",
		"豹変"
	};

	// Token: 0x04001062 RID: 4194
	private static readonly H_VisitorExpression.STATE[] States = new H_VisitorExpression.STATE[]
	{
		H_VisitorExpression.STATE.RESIST,
		H_VisitorExpression.STATE.FLIP
	};

	// Token: 0x04001063 RID: 4195
	private static readonly string[] TypeStrs = new string[]
	{
		"呼吸",
		"台詞"
	};

	// Token: 0x04001064 RID: 4196
	private List<H_VisitorExpressionData.Data_Type> type_datas = new List<H_VisitorExpressionData.Data_Type>();

	// Token: 0x04001065 RID: 4197
	private Dictionary<string, H_VisitorExpressionData.Data_Voice_Set> voice_datas = new Dictionary<string, H_VisitorExpressionData.Data_Voice_Set>();

	// Token: 0x0200023F RID: 575
	public abstract class Data
	{
		// Token: 0x04001066 RID: 4198
		public string eyeType;

		// Token: 0x04001067 RID: 4199
		public string mouthType;

		// Token: 0x04001068 RID: 4200
		public float eyeOpen;

		// Token: 0x04001069 RID: 4201
		public float mouthOpen;
	}

	// Token: 0x02000240 RID: 576
	public class Data_Voice : H_VisitorExpressionData.Data
	{
		// Token: 0x06000F83 RID: 3971 RVA: 0x000630EC File Offset: 0x000612EC
		public Data_Voice(string voice, string eyeType, string mouthType, float eyeOpen, float mouthOpen)
		{
			this.voice = voice;
			this.eyeType = eyeType;
			this.mouthType = mouthType;
			this.eyeOpen = eyeOpen;
			this.mouthOpen = mouthOpen;
		}

		// Token: 0x0400106A RID: 4202
		public string voice;
	}

	// Token: 0x02000241 RID: 577
	private class Data_Voice_Set
	{
		// Token: 0x17000188 RID: 392
		public H_VisitorExpressionData.Data_Voice this[int no]
		{
			get
			{
				return this.list[no];
			}
		}

		// Token: 0x17000189 RID: 393
		// (get) Token: 0x06000F86 RID: 3974 RVA: 0x00063140 File Offset: 0x00061340
		public int Count
		{
			get
			{
				return this.list.Count;
			}
		}

		// Token: 0x06000F87 RID: 3975 RVA: 0x00063150 File Offset: 0x00061350
		public void Add(H_VisitorExpressionData.Data_Voice add)
		{
			this.list.Add(add);
		}

		// Token: 0x0400106B RID: 4203
		private List<H_VisitorExpressionData.Data_Voice> list = new List<H_VisitorExpressionData.Data_Voice>();
	}

	// Token: 0x02000242 RID: 578
	public class Data_Type : H_VisitorExpressionData.Data
	{
		// Token: 0x06000F88 RID: 3976 RVA: 0x00063160 File Offset: 0x00061360
		public Data_Type(string state, string type, string eyeType, string mouthType, float eyeOpen, float mouthOpen)
		{
			this.state = H_VisitorExpressionData.Data_Type.CheckState(state);
			this.type = H_VisitorExpressionData.Data_Type.CheckType(type);
			this.eyeType = eyeType;
			this.mouthType = mouthType;
			this.eyeOpen = eyeOpen;
			this.mouthOpen = mouthOpen;
		}

		// Token: 0x06000F89 RID: 3977 RVA: 0x000631A0 File Offset: 0x000613A0
		private static H_VisitorExpression.STATE CheckState(string str)
		{
			H_VisitorExpression.STATE result = (H_VisitorExpression.STATE)0;
			int i;
			for (i = 0; i < H_VisitorExpressionData.StateStrs.Length; i++)
			{
				if (str == H_VisitorExpressionData.StateStrs[i])
				{
					result = H_VisitorExpressionData.States[i];
					break;
				}
			}
			if (i == H_VisitorExpressionData.StateStrs.Length)
			{
				GlobalData.Debug_LogError("不明状态:" + str);
			}
			return result;
		}

		// Token: 0x06000F8A RID: 3978 RVA: 0x00063204 File Offset: 0x00061404
		private static H_VisitorExpression.TYPE CheckType(string str)
		{
			for (int i = 0; i < H_VisitorExpressionData.TypeStrs.Length; i++)
			{
				if (str == H_VisitorExpressionData.TypeStrs[i])
				{
					return (H_VisitorExpression.TYPE)i;
				}
			}
			GlobalData.Debug_LogError("不明种类:" + str);
			return H_VisitorExpression.TYPE.NUM;
		}

		// Token: 0x0400106C RID: 4204
		public H_VisitorExpression.STATE state;

		// Token: 0x0400106D RID: 4205
		public H_VisitorExpression.TYPE type;
	}
}
